{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e691872f",
   "metadata": {},
   "source": [
    "## models"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1af3af3",
   "metadata": {},
   "source": [
    "- `paraphrase-MiniLM-L6-v2`\n",
    "    - embedding dimension：384 = 32*12"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce91f1d9",
   "metadata": {},
   "source": [
    "```\n",
    "from sentence_transformers import SentenceTransformer, util\n",
    "embed_model = SentenceTransformer('paraphrase-MiniLM-L6-v2')\n",
    "embed_1 = embed_model.encode(sentence1, convert_to_tensor=True)\n",
    "embed_2 = embed_model.encode(sentence2, convert_to_tensor=True)\n",
    "cos_sim = util.pytorch_cos_sim(embed_1, embed_2).item()\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "49d0643d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-08-19T11:43:18.882965Z",
     "start_time": "2023-08-19T11:43:18.551012Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.1806926727294922\n",
      "-0.12082745879888535\n"
     ]
    }
   ],
   "source": [
    "from sentence_transformers import SentenceTransformer, util\n",
    "embed_model = SentenceTransformer('paraphrase-MiniLM-L6-v2')\n",
    "embed_1 = embed_model.encode('the movie is great!', convert_to_tensor=True)\n",
    "embed_2 = embed_model.encode('positive', convert_to_tensor=True)\n",
    "cos_sim = util.pytorch_cos_sim(embed_1, embed_2).item()\n",
    "print(cos_sim)\n",
    "embed_3 = embed_model.encode('negative', convert_to_tensor=True)\n",
    "cos_sim = util.pytorch_cos_sim(embed_1, embed_3).item()\n",
    "print(cos_sim)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
